import request from '@/utils/request'
import { CopyJson } from '@/utils/index'
// import { method } from 'lodash'

/**
 * @description 获取列表所有数据
 */
export function getListAll(params) {
  const data = {
    userId: params.item.userId * 1
  }

  return request({
    url: `queryUserInfoByUserid?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 获取列表
 */
export function getList(params) {
  const data = {
    userId: params.item.userId * 1,
    page: params.page.num,
    dataNum: params.page.size,
    company: params.item.company,
    adminstrative: (params.item.adminstrativeArr.length !== 0) ? params.item.adminstrativeArr.join('/') : '',
    address: params.item.address,
    state: (params.item.state !== '') ? params.item.state : 2,
    startAddTime: (params.item.addTimeArr.length) ? params.item.addTimeArr[0] : '',
    endAddTime: (params.item.addTimeArr.length) ? params.item.addTimeArr[1] : ''
  }
  return request({
    url: `queryUserInfo?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 获取详情
 */
export function getDetail(params) {
  const data = {
    id: params.id * 1
  }
  return request({
    url: `queryUserInfoById?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 添加保存
 * @param {*} params
 */
export function addSave(params) {
  const data = CopyJson(params)
  delete data.adminstrativeArr
  return request({
    url: `addUserInfo?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 编辑保存
 * @param {*} params
 */
export function updateSave(params) {
  const data = CopyJson(params)
  delete data.adminstrativeArr
  return request({
    url: `updataUserInfo?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 删除保存
 * @param {*} params
 */
export function deleteSave(params) {
  const data = CopyJson(params)
  return request({
    url: `delUserInfo?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 根据测点好查询实时数据接口
 */
export function getDetailsByDeviceMac(deviceMac) {
  const data = {
    deviceMac: deviceMac
  }
  return request({
    url: `queryDeviceData?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 根据测点好查询实时数据接口
 */
export function queryDeviceByUserInfoIdPage(params) {
  const data = {
    userInfoId: params,
    page: 999,
    dataNum: 0
  }
  return request({
    url: `queryDeviceByUserInfoIdPage?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 * @description 查询所有设备油烟数据接口
 */
export function queryRealData(params, deviceMac) {
  const data = {
    userId: params * 1,
    deviceMac: deviceMac
  }
  return request({
    url: `queryRealData?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

/**
 *
 * @description 查询登录账户下全部服务商名称信息
 * @param {*} userId  登陆用户ID
 */
export function queryUserInfoAll(userId) {
  const data = {
    userId: userId * 1
  }
  return request({
    url: `queryUserInfoAll?params=${JSON.stringify(data)}`,
    method: 'post'
  })
}

export default {
  getDetail
}
